/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package principal;

import clases.Bloqueo;
import clases.SVCliente;
import static clases.SVCliente.empresa;
import static clases.SVCliente.nombre;
import javax.swing.ImageIcon;

/**
 *
 * @author Juan
 */
public class frmLogin extends javax.swing.JFrame {

    /**
     * Creates new form frmLogin
     */
    public frmLogin() {
        //quita los bordes del JFrame
        this.setUndecorated(true);
        initComponents();
        //evita cerrar Fondo con ALT+C
        this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        //maximiza el Fondo
        this.setExtendedState(MAXIMIZED_BOTH);
        //lo pone siempre al frente
        this.setAlwaysOnTop(true);
        //nueva instancia de bloqueo pasando como para metros este JFrame
        new Bloqueo(this).block();
        try{
          this.setIconImage(new ImageIcon(getClass().getResource("login.png")).getImage());
        
        }catch(Exception e){
            
        }
        txtMaquina.setText("Maquina: "+nombre);
        txtEmpresa.setText("Bienvenidos a "+empresa);
    }
    public static String usuario="";
    public static boolean activo=true;

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        txtMaquina = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        rbAlumno = new javax.swing.JRadioButton();
        rbMaestro = new javax.swing.JRadioButton();
        txtEmpresa = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(0, 153, 153));
        jPanel1.setLayout(new java.awt.GridBagLayout());

        txtMaquina.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        txtMaquina.setForeground(new java.awt.Color(255, 255, 255));
        txtMaquina.setText("Maquina:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 668;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 10);
        jPanel1.add(txtMaquina, gridBagConstraints);

        jPanel2.setBackground(new java.awt.Color(153, 153, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Login"));

        jLabel2.setText("Usuario:");

        txtUsuario.setEnabled(false);
        txtUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUsuarioActionPerformed(evt);
            }
        });

        rbAlumno.setBackground(new java.awt.Color(153, 255, 255));
        rbAlumno.setText("Alumno");
        rbAlumno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbAlumnoActionPerformed(evt);
            }
        });

        rbMaestro.setBackground(new java.awt.Color(153, 255, 255));
        rbMaestro.setText("Maestro");
        rbMaestro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbMaestroActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(4, 4, 4)
                        .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(rbAlumno)
                        .addGap(25, 25, 25)
                        .addComponent(rbMaestro)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel2))
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbAlumno)
                    .addComponent(rbMaestro))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(146, 334, 0, 0);
        jPanel1.add(jPanel2, gridBagConstraints);

        txtEmpresa.setBackground(new java.awt.Color(255, 255, 255));
        txtEmpresa.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        txtEmpresa.setForeground(new java.awt.Color(255, 255, 255));
        txtEmpresa.setText("Bien Venidos a");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 570;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(155, 0, 11, 10);
        jPanel1.add(txtEmpresa, gridBagConstraints);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void rbMaestroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbMaestroActionPerformed
        // TODO add your handling code here:
        usuario="m";
        rbAlumno.setSelected(false);
        txtUsuario.setEnabled(true);
    }//GEN-LAST:event_rbMaestroActionPerformed

    private void rbAlumnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbAlumnoActionPerformed
        usuario="a";
        rbMaestro.setSelected(false);
        txtUsuario.setEnabled(true);
    }//GEN-LAST:event_rbAlumnoActionPerformed

    private void txtUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUsuarioActionPerformed
        if("a".equals(usuario)){
            SVCliente.enviarMensaje(txtUsuario.getText());
            txtUsuario.setText("");
            txtUsuario.setEnabled(false);
            rbAlumno.setSelected(false);
        }
        if("m".equals(usuario)){
            SVCliente.enviarTrama(4, txtUsuario.getText());
            txtUsuario.setText("");
            txtUsuario.setEnabled(false);
            rbMaestro.setSelected(false);
        }
    }//GEN-LAST:event_txtUsuarioActionPerformed

    /**
     * @param args the command line arguments
     */
  // public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
     /*   try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }*/
        //</editor-fold>

        /* Create and display the form */
       /* java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmLogin().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton rbAlumno;
    private javax.swing.JRadioButton rbMaestro;
    public static javax.swing.JLabel txtEmpresa;
    public static javax.swing.JLabel txtMaquina;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables
}
